# Add some methods to the String class
class String

  # Censor swears in string
  def censor
    input = self.split

    # Thank you friends on SO
    result = []
    input.each do |uncensored|
      if Unswear.words.include?(uncensored)
        censored = uncensored.tr("aeiou", "*")
        result.push(censored)
      else
        result.push(uncensored)
      end
    end

    # Join the string together and remove commas
    if result.length > 1
      result = result.join(",").gsub! ",", " "
    else
      result = result.first
    end

    # Return input with censored words
    return result
  end

  # Dangerous censor method
  def censor!
    replace(censor)
  end

  # Method to check if string contains swear
  def swear?
    isSwear = false
    Unswear.words.each do |word|
      isSwear = true if self.downcase.include? word
    end
    # Return if string contains swear or not
    return isSwear
  end

  # Alias swear? with curse?
  alias :curse? :swear?

end
